home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / Miro_Installer.exe / xulrunner / chrome / toolkit.jar / content / mozapps / xpinstall / xpinstallConfirm.js < prev    next >
Encoding:
JavaScript  |  2005-08-25  |  4.0 KB  |  135 lines

  1. //@line 37 "/c/mozilla/toolkit/mozapps/xpinstall/content/xpinstallConfirm.js"
  2.  
  3. var XPInstallConfirm = 
  4.   _param: null
  5. };
  6.  
  7.  
  8. XPInstallConfirm.init = function ()
  9. {
  10.   var _installCountdown;
  11.   var _installCountdownInterval;
  12.   var _focused;
  13.   var _timeout;
  14.  
  15.   var bundle = document.getElementById("xpinstallConfirmStrings");
  16.   
  17.   this._param = window.arguments[0].QueryInterface(Components.interfaces.nsIDialogParamBlock);
  18.   if (!this._param)
  19.     close();
  20.   
  21.   this._param.SetInt(0, 1); // The default return value is "Cancel"
  22.   
  23.   var itemList = document.getElementById("itemList");
  24.   
  25.   var numItemsToInstall = this._param.GetInt(1);
  26.   for (var i = 0; i < numItemsToInstall; ++i) {
  27.     var installItem = document.createElement("installitem");
  28.     itemList.appendChild(installItem);
  29.  
  30.     installItem.name = this._param.GetString(i);
  31.     installItem.url = this._param.GetString(++i);
  32.     var icon = this._param.GetString(++i);
  33.     if (icon != "")
  34.       installItem.icon = icon;
  35.     var cert = this._param.GetString(++i);
  36.     installItem.cert = cert || bundle.getString("Unsigned");
  37.     installItem.signed = cert ? "true" : "false";
  38.   }
  39.   
  40.   var introString = bundle.getString("itemWarningIntroSingle");
  41.   if (numItemsToInstall > 4)
  42.     introString = bundle.getFormattedString("itemWarningIntroMultiple", [numItemsToInstall / 4]);
  43.   if (this._param.objects && this._param.objects.length)
  44.     introString = this._param.objects.queryElementAt(0, Components.interfaces.nsISupportsString).data;
  45.   var textNode = document.createTextNode(introString);
  46.   var introNode = document.getElementById("itemWarningIntro");
  47.   while (introNode.hasChildNodes())
  48.     introNode.removeChild(introNode.firstChild);
  49.   introNode.appendChild(textNode);
  50.   
  51.   var okButton = document.documentElement.getButton("accept");
  52.   okButton.focus();
  53.   okButton.disabled = true;
  54.  
  55.   function okButtonCountdown() {
  56.     _installCountdown -= 1;
  57.  
  58.     if (_installCountdown < 1) {
  59.       okButton.label = bundle.getString("installButtonLabel");
  60.       okButton.disabled = false;
  61.       clearInterval(_installCountdownInterval);
  62.     }
  63.     else
  64.       okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]);
  65.   }
  66.  
  67.   function myfocus() {
  68.     // Clear the timeout if it exists so only the last one will be used.
  69.     if (_timeout)
  70.       clearTimeout(_timeout);
  71.  
  72.     // Use setTimeout since the last focus or blur event to fire is the one we
  73.     // want
  74.     _timeout = setTimeout(setWidgetsAfterFocus, 0);
  75.   }
  76.  
  77.   function setWidgetsAfterFocus() {
  78.     if (_focused)
  79.       return;
  80.  
  81.     _installCountdown = 5;
  82.     _installCountdownInterval = setInterval(okButtonCountdown, 500);
  83.     okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]);
  84.     _focused = true;
  85.   }
  86.  
  87.   function myblur() {
  88.     // Clear the timeout if it exists so only the last one will be used.
  89.     if (_timeout)
  90.       clearTimeout(_timeout);
  91.  
  92.     // Use setTimeout since the last focus or blur event to fire is the one we
  93.     // want
  94.     _timeout = setTimeout(setWidgetsAfterBlur, 0);
  95.   }
  96.  
  97.   function setWidgetsAfterBlur() {
  98.     if (!_focused)
  99.       return;
  100.  
  101.     // Set _installCountdown to the inital value set in setWidgetsAfterFocus
  102.     // plus 1 so when the window is focused there is immediate ui feedback.
  103.     _installCountdown = 6;
  104.     okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]);
  105.     okButton.disabled = true;
  106.     clearInterval(_installCountdownInterval);
  107.     _focused = false;
  108.   }
  109.  
  110.   function myUnload() {
  111.     document.removeEventListener("focus", myfocus, true);
  112.     document.removeEventListener("blur", myblur, true);
  113.     window.removeEventListener("unload", myUnload, false);
  114.   }
  115.  
  116.   document.addEventListener("focus", myfocus, true);
  117.   document.addEventListener("blur", myblur, true);
  118.   window.addEventListener("unload", myUnload, false);
  119.  
  120.   setWidgetsAfterFocus();
  121. }
  122.  
  123. XPInstallConfirm.onOK = function ()
  124. {
  125.   this._param.SetInt(0, 0);
  126.   return true;
  127. }
  128.  
  129. XPInstallConfirm.onCancel = function ()
  130. {
  131.   this._param.SetInt(0, 1);
  132.   return true;
  133. }
  134.